package com.css.fxfzysx.modules.vaolEngineering.controller;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.vaolEngineering.entity.CbVulnerabilityEntity;
import com.css.fxfzysx.modules.vaolEngineering.param.update.BridgeParam;
import com.css.fxfzysx.modules.vaolEngineering.service.CbVulnerabilityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

@RestController
@RequestMapping("cbVulnerability")
@Slf4j
public class CbVulnerabilityController {

    @Autowired
    private CbVulnerabilityService cbVulnerabilityService;


    /**
     * 桥梁易损性计算和保存
     * @param versionId
     * @return
     */
    @GetMapping("cobVulnerability")
    public RestResponse cobVulnerability(String versionId,String tableId,Integer bridgeType){
        return cbVulnerabilityService.cobVulnerability(versionId,tableId,bridgeType);
    }

    /**
     * 数据验证
     */
    @GetMapping("getDataValidation")
    public RestResponse getDataValidation(String versionId){
        try {
            HashMap<Integer, ArrayList<String>> map = cbVulnerabilityService.getDataValidation(versionId);
            return RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("get getDataValidation error:{}",e.getMessage(),e);
            return RestResponse.fail("校验失败!");
        }
    }

    /**
     * 计算
     * @param param
     * @return
     */
    @PostMapping("count")
    public RestResponse count(@RequestBody BridgeParam param){
        try {
            return cbVulnerabilityService.count(param);
        } catch (Exception e) {
            log.error("post count error:{}",e.getMessage(),e);
            return RestResponse.fail("数据异常,计算失败!");
        }
    }
}
